package windows.bet;

import java.util.Arrays;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.ColumnLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.Selector;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.widgets.TextFilter;
import org.uqbar.arena.widgets.TextInputEvent;
import org.uqbar.arena.windows.Dialog;
import org.uqbar.arena.windows.WindowOwner;
import com.uqbar.commons.StringUtils;
import domain.Bet;
import domain.RowBet;
import domain.extra.Row;

public class RowBetWindow extends Dialog<RowBet> {

	public RowBetWindow(WindowOwner parent) {
		super(parent, new RowBet());
	}

	@Override
	protected void executeTask() {
		
	}

	@Override
	protected void addActions(Panel actions) {
		new Button(actions)
		.setCaption("Accept")
		.onClick(new MessageSend(this, ACCEPT))
		.setAsDefault()
		.disableOnError();

		new Button(actions) 
		.setCaption("Cancel")
		.onClick(new MessageSend(this, CANCEL));			
	}

	@Override
	protected void createFormPanel(Panel mainPanel) {
		Panel form = new Panel(mainPanel);
		form.setLayout(new ColumnLayout(2));

		Label betOnLabel = new Label(form);
		betOnLabel.setText("Bet on");
		Row[] element = Row.values();
		new Selector(form).setContents(Arrays.asList(element), "name")
		.bindValueToProperty("strategy");
	
		Label chipsLabel = new Label(form);
		chipsLabel.setText("Chips");
		TextBox chips = new TextBox(form);
		chips.bindValueToProperty(Bet.COUNT);	
		
		TextFilter filter = new TextFilter(){

			public boolean accept(TextInputEvent event) {
				return StringUtils.isBlank(event.getInputText()) || StringUtils.isNumeric(event.getInputText());
			}
									
		}  ;
		chips.withFilter(filter);
	}
	
	protected void createMainTemplate(Panel formBuilder) {
		this.setTitle(" Row Bet ");
		this.setTaskDescription(" Please, select a row");
		super.createMainTemplate(formBuilder);
	}
}
